<?php
/**
 *
 * 版权所有：顺势网站管理系统<www.51shunshi.com>

 * 日    期：2016-01-21
 * 版    本：1.0.0
 * 功能说明：前台控制器演示。
 *
 **/
namespace Home\Controller;

use Vendor\Page;
class EnglishController extends ComController
{
    public function index()
    {
    	$cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
		$this->assign("info",$cate);
		$news =M("category")->order('id asc')->where(array('pid'=>43))->select();
		$this->assign("news",$news);
		//新闻中心
		$order="t desc";
		$listone = M("article_english")->where(array("sid"=>36))->order($order)->limit(1)->find();
		$newslist = M("article_english")->where(array("sid"=>36))->order($order)->limit(1,2)->select();
		$this->assign("listone",$listone);
		$this->assign("newslist",$newslist);
		//产品中心
		$products = M("case_en")->where(array("aid"=>43))->order("time desc")->limit(4)->select();
		$this->assign("products",$products);
		//应用领域
		$list=M("case_en")->where(array("aid"=>43))->order("time desc")->limit(5)->select();
		$this->assign("list",$list);
		$this->display();
	}
	public function about(){
		$cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
		$this->assign("info",$cate);
		$news =M("category")->order('id asc')->where(array('pid'=>43))->select();
		$this->assign("news",$news);
		$this->display();
	}
	public function about01($id){
		$cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
		$this->assign("info",$cate);
		$news =M("category")->order('id asc')->where(array('pid'=>43))->select();
		$this->assign("news",$news);

		$content = M("pages_en")->where(array('id'=>$id))->find();
		$cid=$content['cid'];
		$category = M("page_category_en")->where(array('id'=>$cid))->find();
		// $cate= M("pages")->order("id desc")->where(array('cid'=>$cid))->select();
		$this->assign("content",$content);
		$this->assign("category",$category);
		$this->display("jianjie");
	}
	public function contact(){
		$news =M("category")->order('id asc')->where(array('pid'=>43))->select();
		$this->assign("news",$news);
		$cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
		$this->assign("info",$cate);
		$this->display();
	}

	public function search($k){
		$news =M("category")->order('id asc')->where(array('pid'=>43))->select();
		$this->assign("news",$news);
		$cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
		$this->assign("info",$cate);
        $keywords = !empty($_POST['k']) ? $_POST['k'] : "";
        if(!empty($keywords)){
            $arr = $this->searchBy($keywords);
            if(!empty($arr)){
                $this->assign('num',count($arr['list']));
                $this->assign('list',$arr['list']);
                $this->assign('page',$arr['page']);
                $this->assign('keyword',$keyword);
            }
        }
        $this->display();
        
    }
    //产品中心
    public function product()
    {
    	$news =M("category")->order('id asc')->where(array('pid'=>43))->select();
		$this->assign("news",$news);
    	$cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
		$this->assign("info",$cate);
		$product=M("case_en")->where(array("aid"=>43))->order('time desc')->limit(6)->select();
		$this->assign("product",$product);
		$this->display();
	}
	public function lingyu(){
		$news =M("category")->order('id asc')->where(array('pid'=>43))->select();
		$this->assign("news",$news);
		$cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
		$this->assign("info",$cate);
		$p = intval($p) > 0 ? $p : 1;
        $document = M('case_en');
        $pagesize = 20;#每页数量
        $offset = $pagesize * ($p - 1);//计算记录偏移量
        $where = array('aid'=>44);
        //默认按照时间降序
        $orderby = "time desc";
        $count = $document->where($where)->count();
        $list = $document->where($where)->order($orderby)->limit($offset . ',' . $pagesize)->select();
        $page = new \Think\Page($count, $pagesize);
        $page = $page->show();
        $this->assign('list', $list);
        $this->assign('page', $page);
		$this->display();
	}
	public function fangan(){
		$news =M("category")->order('id asc')->where(array('pid'=>43))->select();
		$this->assign("news",$news);
		$cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
		$this->assign("info",$cate);
		$p = intval($p) > 0 ? $p : 1;
        $document = M('case_en');
        $pagesize = 20;#每页数量
        $offset = $pagesize * ($p - 1);//计算记录偏移量
        $where = array('aid'=>49);
        //默认按照时间降序
        $orderby = "time desc";
        $count = $document->where($where)->count();
        $list = $document->where($where)->order($orderby)->limit($offset . ',' . $pagesize)->select();
        $page = new \Think\Page($count, $pagesize);
        $page = $page->show();
        $this->assign('list', $list);
        $this->assign('page', $page);
		$this->display("chanpinku");
	}
	public function chanpinku(){
		$news =M("category")->order('id asc')->where(array('pid'=>43))->select();
		$this->assign("news",$news);
		$cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
		$this->assign("info",$cate);
		$p = intval($p) > 0 ? $p : 1;
        $document = M('case_en');
        $pagesize = 20;#每页数量
        $offset = $pagesize * ($p - 1);//计算记录偏移量
        $where = array('aid'=>43);
        //默认按照时间降序
        $orderby = "time desc";
        $count = $document->where($where)->count();
        $list = $document->where($where)->order($orderby)->limit($offset . ',' . $pagesize)->select();
        $page = new \Think\Page($count, $pagesize);
        $page = $page->show();
        $this->assign('list', $list);
        $this->assign('page', $page);
		$this->display();
	}
	public function pages($id){
		$news =M("category")->order('id asc')->where(array('pid'=>43))->select();
		$this->assign("news",$news);
		$cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
		$this->assign("info",$cate);
		$article=M("case_en")->find($id);
		// var_dump($list);exit;
    	$sid=$article['aid'];
    	$where1 = "id< $id";
        $where2 = "id> $id";
        $map['aid'] = array('eq',$sid);
    	$pre=M("case_en")->where($map)->where($where1)->order("id desc")->find();
        $next=M('case_en')->where($map)->where($where2)->order("id asc")->find();
        M('case_en')->where("id=$id")->setInc('c',1);
        $info = M("acategory")->where(array("id"=>$sid))->find();
        $this->assign("in",$info);
    	$this->assign("case",$article);
		$this->assign('pre',$pre);
		$this->assign('next',$next);
		$this->display();
	}

	//新闻中心
	 public function news_index()
    {
    	$cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
		$this->assign("info",$cate);
		$news =M("category")->order('id asc')->where(array('pid'=>43))->select();
		$this->assign("news",$news);
		$this->display("news");
	}
	public function news($id){
		$cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
		$this->assign("info",$cate);
		$news =M("category")->order('id asc')->where(array('pid'=>43))->select();
		$this->assign("news",$news);
		$id=$_GET['id'];
    	$p = isset($_GET['p']) ? intval($_GET['p']) : '1';
    	$order = 'aid desc';
    	$adviser = M('article_english');
    	$pagesize =10;//每页数量
    	$offset = $pagesize * ($p - 1);//计算记录偏移量
    	$list=$adviser->where(array('sid'=>$id))->select();
    	$count = $adviser->where(array('sid'=>$id))->count();
    	$list = $adviser->order($order)->where(array('sid'=>$id))->limit($offset . ',' . $pagesize)->select();
        // var_dump($list);exit;
    	//最新的一条文章
    	$content = $adviser->order("t desc")->where(array('sid'=>$id))->limit(1)->find();
        $mid=$content['sid'];
        $info=M("category")->where(array("id"=>$mid))->find();
    	$page = new \Think\Page($count, $pagesize);
    	$page = $page->show();
        $this->assign("in",$info);
    	$this->assign("content",$content);
    	$this->assign('list',$list);
    	$this->assign('page',$page);
		$this->display("hangye");
	}

	public function article($aid){
		$news =M("category")->order('id asc')->where(array('pid'=>43))->select();
		$this->assign("news",$news);
		$cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
		$this->assign("info",$cate);
		$article=M("article_english")->find($aid);
    	$sid=$article['sid'];
    	$where1 = "aid< $aid";
        $where2 = "aid> $aid";
        $map['sid'] = array('eq',$sid);
    	$pre=M("article_english")->where($map)->where($where1)->order("aid desc")->find();
        $next=M('article_english')->where($map)->where($where2)->order("aid asc")->find();
        $info=M("category")->where(array("id"=>$sid))->find();
        $this->assign("in",$info);
        M('article_english')->where("aid=$aid")->setInc('n',1);
    	$this->assign("article",$article);
		$this->assign('pre',$pre);
		$this->assign('next',$next);
		$this->display();
	}

	//服务中心
	public function service()
    {
      $news =M("category")->order('id asc')->where(array('pid'=>43))->select();
    $this->assign("news",$news);
    	$cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
		$this->assign("info",$cate);

		$this->display();
	}
	public function zhichi(){
    $news =M("category")->order('id asc')->where(array('pid'=>43))->select();
    $this->assign("news",$news);
		$cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
		$this->assign("info",$cate);
    $info =M("pages_en")->where(array("cid"=>2))->find();
    $this->assign("info",$info);
		$this->display();
	}
	public function fankui(){
    $news =M("category")->order('id asc')->where(array('pid'=>43))->select();
    $this->assign("news",$news);
		$cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
		$this->assign("info",$cate);
		$this->display();
	}
	public function wendang($p = 0){
    $news =M("category")->order('id asc')->where(array('pid'=>43))->select();
    $this->assign("news",$news);
		$cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
		$this->assign("info",$cate);
		$p = intval($p) > 0 ? $p : 1;
        $document = M('document_en');
        $pagesize = 20;#每页数量
        $offset = $pagesize * ($p - 1);//计算记录偏移量
        $where = '1 = 1 ';
        //默认按照时间降序
        $orderby = "time desc";
        $count = $document->where($where)->count();
        $list = $document->where($where)->order($orderby)->limit($offset . ',' . $pagesize)->select();
        $page = new \Think\Page($count, $pagesize);
        $page = $page->show();
        $this->assign('list', $list);
        $this->assign('page', $page);
		$this->display();
	}
	public function downfile(){
    if(isset($_GET['id'])){
      $data=M("document_en")->where('id='.$_GET['id'])->field('path,title')->find();
      $filename=$data['path'];//获取文件的相对路径
      $title=$data['title'];//获取文件的名称，必须带后缀格式
    }
    $filename="./Public/".$filename;
   Header( "Content-type:  application/octet-stream ");
   Header( "Accept-Ranges:  bytes ");
   Header( "Accept-Length: " .filesize($filename));
   header( "Content-Disposition:  attachment;  filename= $title");//如果没带格式将生成不知道什么格式的文件
   readfile($filename);
    }

    public function saveMsg(){
      $in = I();
      $data = array(
        'name'=>$in['name'],
        'contacts'=>$in['contacts'],
        'country'=>$in['country'],
        'sex'=>$in['sex'],
        'sebsite'=>$in['sebsite'],
        'tel'=>$in['tel'],
        'content'=>$in['content'],
        'email'=>$in['email'],
        'time'=>date("Y-m-d H:i:s"),
        );
      if (!$data['name'] or !$data['tel'] or !$data['content']) {
            $this->error('警告！公司名称、联系电话及反馈内容为必填项目。');
        }
      $result=M("message")->add($data);
      if($result){
       
          $this->success('恭喜！反馈成功！请耐心等待我们的工作人员联系您');
      }else{
       
            $this->error('很遗憾！反馈失败，请重新反馈！');
      }
    }
    public function searchs($p=1){
      $keyword = !empty($_GET['k']) ? $_GET['k'] : "";
      if(!empty($keyword)){
        $p = intval($p) > 0 ? $p : 1;
            $pagesize = 20;#每页数量
            $offset = $pagesize * ($p - 1);//计算记录偏移量
            $articleDB = M('document_en as a');
            $orderby = "a.id DESC";
            $map['a.title'] = array('like',"%".$keyword."%");
            $prefix = C('DB_PREFIX');
            $field = "a.id,a.title";
            $count = $articleDB->where($map)->count();
            $list = $articleDB
                ->field($field)
                ->where($map)
                ->order($orderby)
                ->limit($offset . ',' . $pagesize)
                ->select();
            $page = new \Think\Page($count, $pagesize);
            $page = $page->show();
      }
      $this->assign("list",$list);
      $this->assign("page",$page);
      $this->display("wendang");
    }
    //创新实验室
    public function creat()
    {
    	$cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
		$this->assign("info",$cate);
		$news =M("category")->order('id asc')->where(array('pid'=>43))->select();
    	$this->assign("news",$news);
    	$p = intval($p) > 0 ? $p : 1;
        $article = M('article_english');
        $pagesize = 20;#每页数量
        $offset = $pagesize * ($p - 1);//计算记录偏移量
        $where = array('sid'=>40);
        //默认按照时间降序
        $orderby = "t desc";
        $count = $article->where($where)->count();
        $list = $article->where($where)->order($orderby)->limit($offset . ',' . $pagesize)->select();
        $page = new \Think\Page($count, $pagesize);
        $page = $page->show();
        $content = $article ->order($orderby)->where($where)->limit(1)->find();
        $this->assign("content",$content);
        $this->assign('list', $list);
        $this->assign('page', $page);
		$this->display();
	}
    public function c_pages($id){
        $cate= M("pages_en")->order("id asc")->where(array('cid'=>1))->select();
        $this->assign("info",$cate);
        $news =M("category")->order('id asc')->where(array('pid'=>43))->select();
        $this->assign("news",$news);

        $content = M("pages_en")->where(array('id'=>$id))->find();
        $cid=$content['cid'];
        $category = M("page_category_en")->where(array('id'=>$cid))->find();
        $list= M("pages_en")->order("id desc")->where(array('cid'=>$cid))->select();
        $this->assign("content",$content);
        $this->assign("category",$category);
        $this->assign("list",$list);
        $this->display("shiyan");
    }
}